
package com.market.web.action;

import java.util.List;

import org.springframework.beans.BeanUtils;

import com.market.bean.Customer;
import com.market.constant.Constant;
import com.market.web.form.CusSearchForm;
import com.market.web.form.CustomerForm;
import com.market.web.tag.Pages;
import com.market.web.utils.ListUtils;

public class AdminCusSearchAction extends BaseAction2
{
    private static int perPage = 30;

    private String name = "";

    private String sex = "";

    private int level = -1;

    private String address = "";

    private String id = "";

    public String getAddress()
    {
        return address;
    }

    public void setAddress(String address)
    {
        this.address = address;
    }

    public String getId()
    {
        return id;
    }

    public void setId(String id)
    {
        this.id = id;
    }

    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public String getSex()
    {
        return sex;
    }

    public void setSex(String sex)
    {
        this.sex = sex;
    }

    public int getLevel()
    {
        return level;
    }

    public void setLevel(int level)
    {
        this.level = level;
    }
    
    public String execute() throws Exception
    {
        // CusSearchForm csf = (CusSearchForm)form;
        int curP = (int)getLong("page");
        if (curP == 0)
        {
            curP++;
        }
        CusSearchForm csf  = new  CusSearchForm();
        BeanUtils.copyProperties(this, csf);
        List<Object> list = getCustomerService().findByForm(csf, (curP - 1) * perPage, perPage);
        System.out.println("size:" + list.size());
        int count = getCustomerService().getCountByForm(csf);
        StringBuffer path = new StringBuffer();
        path.append(getRequest().getServletPath()).append(".do?name=").append(getName()).append("&address=").append(
                getAddress()).append("&id=").append(getId()).append("&sex=").append(getSex()).append(
                "&level=").append(getLevel());
        Pages pages = new Pages();
        pages.setCurPage(curP);
        pages.setPerPage(perPage);
        pages.setRowCount(count);
        pages.setPath(path.toString());
        getRequest().setAttribute(Constant.PAGES, pages);
        getRequest().setAttribute("customer", ListUtils.convert(list, Customer.class, CustomerForm.class));
        return SUCCESS;
        //return mapping.findForward("customer");
    }
}
